﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using Server_NhaSach.DataAccess.HelperLayer;

namespace Server_NhaSach.DataAccess.LogicLayer
{
    [Serializable]
    public class DatHangOnlineDAO
    {
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion

        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
        }
        #endregion

        #region "Khai báo các Method"
        public bool InsertDHOL(DatHangOnlineDTO DatHangOnline)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[6];
            par[0] = new SqlParameter("@MaDHOL", DatHangOnline.MaDHOL);
            par[1] = new SqlParameter("@MaTKOL", DatHangOnline.MaTKOL);
            par[2] = new SqlParameter("@NgayDH", DatHangOnline.NgayDH);
            par[3] = new SqlParameter("@HinhThucThanhToan", DatHangOnline.HinhThucThanhToan);
            par[4] = new SqlParameter("@TrangThai", DatHangOnline.TrangThai);
            par[5] = new SqlParameter("@TongTien", DatHangOnline.TongTien);
            try
            {
                helper.InsertQuery("sp_Insert_DatHangOnline", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool UpdateDHOL(DatHangOnlineDTO DatHangOnline)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[6];
            par[0] = new SqlParameter("@MaDHOL", DatHangOnline.MaDHOL);
            par[1] = new SqlParameter("@MaTKOL", DatHangOnline.MaTKOL);
            par[2] = new SqlParameter("@NgayDH", DatHangOnline.NgayDH);
            par[3] = new SqlParameter("@HinhThucThanhToan", DatHangOnline.HinhThucThanhToan);
            par[4] = new SqlParameter("@TrangThai", DatHangOnline.TrangThai);
            par[5] = new SqlParameter("@TongTien", DatHangOnline.TongTien);
            try
            {
                helper.UpdateQuery("sp_Update_DatHangOnline", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool DeleteDHOL(string maDHOL)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("@maDHOL", maDHOL);
            try
            {
                helper.DeleteQuery("sp_Delete_DatHangOnline", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public DataSet LayDS_DatHangOnline()
        {
            helper = new Helper();
            DataSet ds_dhol = helper.SelectQuery("sp_LayDS_DatHangOnline");
            return ds_dhol;
        }
        #endregion
    }
}